/*
 * Copyright (c) 2008-2010, Petr Panteleyev
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *    2. Redistributions in binary form must reproduce the above copyright notice,
 *       this list of conditions and the following disclaimer in the documentation
 *       and/or other materials provided with the distribution.
 *    3. The name of the author may not be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.panteleyev.blogclient;

import java.awt.Toolkit;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;

/**
 *
 * @author Petr Panteleyev
 */
public class BloggingKit {
    public static class CopyAction extends DefaultEditorKit.CopyAction {
        public CopyAction() {
            putValue(Action.NAME, L10N.MAIN_FRAME_COPY_ACTION.s());
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, getKeyMask()));
            putValue(Action.SMALL_ICON, Icon.COPY.i());
            putValue(Action.LARGE_ICON_KEY, Icon.COPY.I());
            putValue(Action.SHORT_DESCRIPTION, L10N.MAIN_FRAME_COPY_ACTION.s());
        }
    };

    public static class CutAction extends DefaultEditorKit.CutAction {
        public CutAction() {
            putValue(Action.NAME, L10N.MAIN_FRAME_CUT_ACTION.s());
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, getKeyMask()));
            putValue(Action.SMALL_ICON, Icon.CUT.i());
            putValue(Action.LARGE_ICON_KEY, Icon.CUT.I());
            putValue(Action.SHORT_DESCRIPTION, L10N.MAIN_FRAME_CUT_ACTION.s());
        }
    }

    public static class PasteAction extends DefaultEditorKit.PasteAction {
        public PasteAction() {
            putValue(Action.NAME, L10N.MAIN_FRAME_PASTE_ACTION.s());
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, getKeyMask()));
            putValue(Action.SMALL_ICON, Icon.PASTE.i());
            putValue(Action.LARGE_ICON_KEY, Icon.PASTE.I());
            putValue(Action.SHORT_DESCRIPTION, L10N.MAIN_FRAME_PASTE_ACTION.s());
        }
    }

    public static abstract class UndoAction extends AbstractAction {
        public UndoAction() {
            super(L10N.MAIN_FRAME_UNDO_ACTION.s(), Icon.UNDO.i());
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z, getKeyMask()));
            putValue(Action.SHORT_DESCRIPTION, L10N.MAIN_FRAME_UNDO_ACTION.s());
            putValue(Action.LARGE_ICON_KEY, Icon.UNDO.I());
        }
    }

    public static abstract class RedoAction extends AbstractAction {
        public RedoAction() {
            super(L10N.MAIN_FRAME_REDO_ACTION.s(), Icon.REDO.i());
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Y, keyMask));
            putValue(Action.SHORT_DESCRIPTION, L10N.MAIN_FRAME_REDO_ACTION.s());
            putValue(Action.LARGE_ICON_KEY, Icon.REDO.I());
        }
    }

    public static abstract class PostWindowPreviewAction extends AbstractAction {
        public PostWindowPreviewAction() {
            super(L10N.POST_WINDOW_PREVIEW_ACTION.s());
            putValue(Action.SHORT_DESCRIPTION, L10N.POST_WINDOW_PREVIEW_ACTION.s());
        }
    }

    public static abstract class PostWindowPublishAction extends AbstractAction {
        public PostWindowPublishAction() {
            super(L10N.POST_WINDOW_PUBLISH_ACTION.s());
            putValue(Action.SHORT_DESCRIPTION, L10N.POST_WINDOW_PUBLISH_ACTION.s());
        }
    }

    public static abstract class PostWindowDeleteAction extends AbstractAction {
        public PostWindowDeleteAction() {
            super(L10N.POST_WINDOW_DELETE_ACTION.s());
            putValue(Action.SHORT_DESCRIPTION, L10N.POST_WINDOW_DELETE_ACTION.s());
        }
    }

    public static abstract class HistoryWindowCopyEntryLinkAction extends AbstractAction {
        public HistoryWindowCopyEntryLinkAction() {
            super(L10N.HISTORY_WINDOW_COPY_ENTRY_LINK_ACTION.s(), Icon.COPY.i());
            putValue(Action.SHORT_DESCRIPTION, L10N.HISTORY_WINDOW_COPY_ENTRY_LINK_ACTION.s());
        }
    }

    public static abstract class HistoryWindowOpenEntryLinkAction extends AbstractAction {
        public HistoryWindowOpenEntryLinkAction() {
            super(L10N.HISTORY_WINDOW_OPEN_ENTRY_LINK_ACTION.s(), Icon.EARTH.i());
            putValue(Action.SHORT_DESCRIPTION, L10N.HISTORY_WINDOW_OPEN_ENTRY_LINK_ACTION.s());
            putValue(Action.LARGE_ICON_KEY, Icon.EARTH.I());
        }
    }

    private static int keyMask;

    public static int getKeyMask() {
        return keyMask;
    }

    static {
        keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    }
}
